<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE xsl:stylesheet SYSTEM "lang://photos">

<xsl:stylesheet
	version="1.0"
	xmlns:php="http://php.net/xsl"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
		
	<xsl:include href="../main.xsl" />
	<xsl:include href="menu.xsl" />
	<xsl:include href="../common/navigation.xsl" />
	<xsl:include href="blocks.xsl" />
	
	<!-- Запускаем рендер страницы -->
	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
			<link rel="stylesheet" href="{$baseURI}/css/photos.css" type="text/css" media="all" />
			<script type="text/javascript" src="{$baseURI}/js/photos.js" />
		</head>
		<body>
			
			<xsl:call-template name="top-userbar" />
			
			<!-- Header -->
			<div id="header">
				<xsl:call-template name="logo" />
				
				<!-- Menu -->
				<xsl:call-template name="menu" />
			</div>
			<!-- /Header -->
			
			<!-- Blocks -->
			<div id="blocks">
				<div id="blocks_inner">
					<xsl:call-template name="default-blocks-top" />
					
					<div class="block">
						<h4>&labelBlockCloud;</h4>
						<p>
							<xsl:apply-templates select="document('xmodule://photos/getTagsCloud')/data/response/tags" mode="block-tags-cloud" />
						</p>
					</div>
				</div>
			</div>
			<!-- // Blocks -->
			
			<!-- Content -->
			<div id="content">
				<div id="content_inner">
					<xsl:apply-templates select="response" />
				</div>
			</div>
			<!-- // Content -->
			
			<!-- Address -->
			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	
	
	<!-- RESPONSE -->
	<xsl:template match="response">
		<xsl:if test="../@method = 'user'">
			<xsl:apply-templates select="document(concat('xobject://user/', @user-id))/data/object" mode="owner-bar" />
		</xsl:if>
		<xsl:if test="../@method != 'user'">
			<h1>&labelAlbums;</h1>
		</xsl:if>
			
		<xsl:if test="count(object) = 0">
			<p>
				<xsl:text>&labelAlbumsEmpty;.</xsl:text>
				<xsl:if test="../@method = 'user' and @user-id = $userId">
					<xsl:text> </xsl:text>
					<input type="button" value="&labelCreateAlbumButton;" onclick="document.location.href='{$baseURI}/photos/create_album'" />
				</xsl:if>
			</p>
		</xsl:if>
		
		<xsl:if test="count(object) != 0">
			<div id="photoalbums_list">
				<xsl:apply-templates select="object">
					<xsl:with-param name="userId" select="../@user-id" />
					<xsl:with-param name="userGroup" select="../@user-group" />
				</xsl:apply-templates>
			</div>
			
			<xsl:apply-templates select="pages" mode="pages-navigation">
				<xsl:with-param name="href">
					<xsl:choose>
						<xsl:when test="../@method = 'user'">
							<xsl:value-of select="concat ($baseURI, '/photos/user/', @user-login)" />
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="$baseURI" />
							<xsl:text>/photos</xsl:text>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:with-param>
			</xsl:apply-templates>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="object[@type='photoalbum']">
		<xsl:param name="userId" />
		<xsl:param name="userGroup" />
		<xsl:param name="id" select="@id" />
		<xsl:param name="userLogin" select="property[@name='user_login']/value" />
		
		<div class="album_item">
			<div class="album_preview">
				<a href="{$baseURI}/photoalbum/{$id}">
					<img>
						<xsl:attribute name="src">
							<xsl:choose>
								<xsl:when test="property[@name='preview']/value = ''">
									<xsl:value-of select="$baseURI" />
									<xsl:text>/images/default-photoalbum-preview.png</xsl:text>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="concat ($baseURI, '/thumb_100_100', property[@name='preview']/value)" />
								</xsl:otherwise>
							</xsl:choose>
						</xsl:attribute>
						<xsl:attribute name="alt">
							<xsl:value-of select="property[@name='title']/value" />
						</xsl:attribute>
					</img>
				</a>
			</div>
			<div class="album_info">
				<h3>
					<a href="{$baseURI}/photoalbum/{$id}">
						<xsl:value-of select="property[@name='title']/value" />
					</a>
					
					<xsl:if test="property[@owner_id]/value = $userId or $userGroup = 'admin' or $userGroup = 'moderator'">
						<span>
							<a href="{$baseURI}/photos/edit_album/{$id}">
								<img src="{$baseURI}/images/settings-icon.png" alt="" />
							</a>
							<xsl:text> </xsl:text>
							<a onclick="if(!confirm('&labelAlbumDeleteConfirm;'))return false;" href="{$baseURI}/photos/delete_album/{$id}">
								<img src="{$baseURI}/images/delete-icon.png" alt="" />
							</a>
						</span>
					</xsl:if>
				</h3>
				<div class="owner">
					<xsl:text>&labelAuthor;: </xsl:text>
					<a href="{$baseURI}/users/{$userLogin}">
						<xsl:value-of select="property[@name='user_name']/value" />
					</a>
				</div>
				<div class="count_photos">
					<xsl:value-of select="php:functionString ('XSLTGetNumWithCase', property[@name='count_photos']/value, '&labelPhotoPad1;', '&labelPhotoPad2;', '&labelPhotoPad3;')" />
				</div>
				<div class="description">
					<xsl:value-of select="property[@name='description']/value" />
				</div>
			</div>
		</div>
	</xsl:template>
	
	<!-- OWNER BAR -->
	<xsl:template match="object[@type='user']" mode="owner-bar">
		<xsl:param name="id" select="@id" />
		<xsl:param name="userLogin" select="property[@name='login']/value" />
		
		<div id="photoalbums_owner_info">
			<div id="owner_avatar">
				<a href="{$baseURI}/user/{$userLogin}">
					<img>
						<xsl:attribute name="src">
							<xsl:if test="property[@name='avatar']/value = ''">
								<xsl:value-of select="concat ($baseURI, '/images/default-avatar.png')" />
							</xsl:if>
							<xsl:if test="property[@name='avatar']/value != ''">
								<xsl:value-of select="concat ($baseURI, '/thumb_50_50', property[@name='avatar']/value)" />
							</xsl:if>
						</xsl:attribute>
						<xsl:attribute name="alt">
							<xsl:value-of select="property[@name='name']/value" />
						</xsl:attribute>
					</img>
				</a>
			</div>
			<div id="owner_info">
				<h3>
					<xsl:text>&labelAlbumsOfUser; </xsl:text>
					<a href="{$baseURI}/user/{$userLogin}">
						<xsl:value-of select="property[@name='name']/value" />
					</a>
				</h3>
				<div id="owner_menu">
					<a href="{$baseURI}/user/{$userLogin}">&labelUserProfile;</a>
					<a href="{$baseURI}/blogs/user/{$userLogin}">&labelUserBlog;</a>
					<a href="{$baseURI}/photos/user/{$userLogin}" class="selected">&labelUserPhotos;</a>
				</div>
			</div>
		</div>
	</xsl:template>
	
</xsl:stylesheet>